<template>
  <base-breadcrumb>
    <a-card
      :bordered="false"
      style="over-flow:scroll"
    >
      <title-name
        v-if="type=='add'"
        title="新增设计策划计划表"
      />
      <title-name
        v-if="type=='edit'"
        title="编辑设计策划计划表"
      />
      <title-name
        v-if="type=='view'"
        title="查看设计策划计划表"
      />

      <a-form-model
        ref="ruleForm"
        :rules="rules"
        :model="form"
        :label-col="{lg: {span: 6}, sm: {span:6}}"
        :wrapper-col="{lg: {span: 18}, sm: {span: 18} }"
      >
        <a-row>
          <a-col
            :md="16"
            :sm="16"
          >
            <a-form-model-item
              label="所属单位"
              :label-col="{lg: {span: 6}, sm: {span:6}}"
              :wrapper-col="{lg: {span: 18}, sm: {span: 18} }"
              prop="projectId"
            >
              <org-tree-select
                v-model="form.projectId"
                is-need-auth
                :isAutoSelectFirst="type=='add'"
                is-special-tree
                :is-query-projec-detail="false"
                check-strictly
                :extra-query="{
                  designTypeNames: ['B类', 'C类'],
                  ifDesignPlan: 1
                }"
                :exclude-business-set="type!=='add'? [$route.query.id]: []"
                :disabled="type==='view' || type==='approve'"
                @select="selectOrg"
                @handleChange="handleOrgChange"
              />
            </a-form-model-item>
          </a-col>
          <!--          <a-col-->
          <!--            :md="8"-->
          <!--            :sm="8"-->
          <!--          >-->
          <!--            <a-form-model-item-->
          <!--              label="分公司"-->
          <!--              :label-col="{lg: {span: 6}, sm: {span:6}}"-->
          <!--              :wrapper-col="{lg: {span: 18}, sm: {span: 18} }"-->
          <!--              prop="branchCompany"-->
          <!--            >-->
          <!--              <SelectSubCompany-->
          <!--                v-model="form.branchCompany"-->
          <!--                placeholder="请选择"-->
          <!--                :disabled="type=='view' || type=='approve'"-->
          <!--                @change="clearData"-->
          <!--              />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col-->
          <!--            :md="8"-->
          <!--            :sm="8"-->
          <!--          >-->
          <!--            <a-form-model-item-->
          <!--              label="项目名称"-->
          <!--              prop="projectId"-->
          <!--            >-->
          <!--              <a-select-->
          <!--                v-model="form.projectId"-->
          <!--                placeholder="请选择"-->
          <!--                :get-popup-container="getPopupContainer"-->
          <!--                :disabled="type=='view' || type=='approve'"-->
          <!--                @focus="getProjectTypes"-->
          <!--                @change="changeProjectType(form.projectId)"-->
          <!--              >-->
          <!--                <a-icon-->
          <!--                  v-if="loadingState.isProject"-->
          <!--                  slot="suffixIcon"-->
          <!--                  style="color: #096dd9"-->
          <!--                  type="loading"-->
          <!--                />-->
          <!--                <a-spin-->
          <!--                  v-if="loadingState.isProject"-->
          <!--                  slot="notFoundContent"-->
          <!--                  size="small"-->
          <!--                />-->
          <!--                <a-select-option-->
          <!--                  v-for="item in realProjectList"-->
          <!--                  :key="item.projectId"-->
          <!--                  :value="item.projectId"-->
          <!--                >-->
          <!--                  {{ item.projectName }}-->
          <!--                </a-select-option>-->
          <!--              </a-select>-->
          <!--              &lt;!&ndash; <SelectProject-->
          <!--                      placeholder="请选择"-->
          <!--                      :disabled="type=='view' || type=='approve'"-->
          <!--                      v-model="form.projectId"-->
          <!--                      :form="form"-->
          <!--                      :isClear="true"-->
          <!--                      :customQuery="{-->
          <!--                        designTypeNames: ['B类', 'C类'],-->
          <!--                        ifDesignPlan: 0-->
          <!--                      }"-->
          <!--                      @focus="getProjectTypes"-->
          <!--                      @change="changeProjectType(form.projectId)"-->
          <!--                      keyValue="branchCompany"></SelectProject> &ndash;&gt;-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="项目编号"
              prop="num"
            >
              <BaseInput
                v-model="form.num"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="项目设计管理类别"
              prop="designType"
            >
              <BaseInput
                v-model="form.designType"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="项目进场时间"
              prop="inTime"
            >
              <a-date-picker
                v-model="form.inTime"
                :disabled="type=='view' || type=='approve'"
                @change="changeTime"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="创建人"
              prop="personName"
            >
              <BaseInput
                v-model="form.personName"
                disabled
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-model-item
              label="创建时间"
              prop="member"
            >
              <BaseInput
                v-model="form.time"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <div>
        <a-row>
          <a-col
            :md="24"
            :sm="19"
          >
            <div class="table-operator">
              <a-row>
                <a-col
                  :md="24"
                  :sm="24"
                >
                  <a-button
                    :disabled="type=='view'|| type=='approve'"
                    type="primary"
                    @click="goAdd()"
                  >
                    新增计划项
                  </a-button>
                  <a-button
                    :disabled="type=='view'|| type=='approve' || !tableData.length"
                    type="primary"
                    @click="goDel()"
                  >
                    删除
                  </a-button>
                </a-col>
              </a-row>
            </div>
            <a-table
              v-if="type=='view'"
              ref="table"
              row-key="row.id"
              :columns="columns"
              :pagination="false"
              :data-source="tableData"
            >
              <span
                slot="serial"
                slot-scope="text, record, index"
              >{{ index + 1 }}</span>
              <span
                slot="action"
                slot-scope="text, record,index"
              >
                <template>
                  <!-- <a @click="handleSub(record,'view')">查看</a>
                  <a-divider type="vertical"/> -->
                  <a
                    v-if="type=='add'||type=='edit'"
                    @click="handleEdit(record,index)"
                  >编辑</a>
                </template>
              </span>
            </a-table>
            <a-table
              v-else
              ref="table"
              row-key="row.id"
              :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
              :columns="columns"
              :pagination="false"
              :data-source="tableData"
            >
              <span
                slot="serial"
                slot-scope="text, record, index"
              >{{ index + 1 }}</span>
              <span
                slot="action"
                slot-scope="text, record,index"
              >
                <template>
                  <!-- <a @click="handleSub(record,'view')">查看</a>
                  <a-divider type="vertical"/> -->
                  <a
                    v-if="type=='add'||type=='edit'"
                    @click="handleEdit(record,index)"
                  >编辑</a>
                </template>
              </span>
              <span
                slot="posts"
                slot-scope="text, record,index"
              >
                <ellipsis
                  :length="20"
                  tooltip
                >{{ text }}</ellipsis>
              </span>
            </a-table>
          </a-col>
        </a-row>
      </div>
    </a-card>

    <a-card v-if="type=='approve'">
      <title-name title="审批信息" />
      <a-form>
        <a-row>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="最后审批结果"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput disabled />
            </a-form-item>
          </a-col>
          <a-col
            :md="8"
            :sm="8"
          >
            <a-form-item
              label="最后审批时间"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput disabled />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <title-name title="审批流程信息" />

      <div class="btns-wrapp mb20">
        <a-button
          type="primary"
          @click="visibleState.auditProcess = true"
        >
          审批流程图
        </a-button>
      </div>

      <a-table
        pagination="false"
        bordered
        row-key="id"
        :columns="columnApprove"
        :data-source="dataSource"
      >
        <span
          slot="operation"
          slot-scope="text, record"
        >
          <template>
            <a @click="handleSub(record)">查看</a>
          </template>
        </span>
      </a-table>
    </a-card>


    <div class="footer page-btn-right-top">
      <a-button
        v-if="type=='add' || type=='edit'"
        type="primary"
        :loading="loadingState.isDraft"
        @click="saveForm()"
      >
        保存草稿
      </a-button>
      <a-button
        v-if="type=='add' || type=='edit'"
        type="primary"
        :loading="loadingState.isSubmit"
        @click="saveSubmit()"
      >
        提交
      </a-button>
      <a-button
        type="default"
        @click="goBack"
      >
        关闭
      </a-button>
    </div>

    <a-modal
      :title="titleName"
      :visible="visible"
      :confirm-loading="confirmLoading"
      width="1000px"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <a-form-model
        ref="ruleForm1"
        :rules="rules1"
        :model="formAdd"
      >
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="计划事项"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="matter"
            >
              <BaseInput
                v-model="formAdd.matter"
                :disabled="type=='view'"
                :max-length="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>

          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="计划时间"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="time"
            >
              <a-date-picker
                v-model="formAdd.time"
                :disabled="type=='view'"
                @change="changeTimes"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="责任人"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
              prop="personId"
            >
              <a-select
                v-model="formAdd.personId"
                placeholder="请选择"
                show-search
                :filter-option="filterOption"
                :get-popup-container="getPopupContainer"
                :disabled="type=='view'"
                @change="changePerson"
              >
                <a-icon
                  slot="suffixIcon"
                  type="search"
                />
                <a-spin
                  v-if="loading"
                  slot="notFoundContent"
                  size="small"
                />
                <a-select-option
                  v-for="item in personList"
                  :key="item.id"
                >
                  {{ item.name }}
                </a-select-option>
              </a-select>
              <!-- <SelectDutyPeople @change="changePerson" :form="formAdd" keyValue="branchId" placeholder="请选择" v-model="formAdd.person" :isClear="false"></SelectDutyPeople> -->
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-model-item
              label="责任人岗位"
              :label-col="{ lg: { span: 6 }, sm: { span: 6 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formAdd.posts"
                :title="formAdd.posts"
                disabled
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>

    <a-modal
      v-model="approveVisible"
      width="700px"
      title="审批信息详情"
    >
      <template slot="footer">
        <a-button
          key="back"
          @click="handleCancel"
        >
          关闭
        </a-button>
      </template>
      <a-form
        ref="form2"
        :model="formApprove"
      >
        <a-row :gutter="24">
          <a-col
            :md="24"
            :sm="24"
          >
            <a-form-item
              label="审批意见"
              :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formApprove.remark"
                type="textarea"
                disabled
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-item
              label="审批人"
              :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formApprove.replier"
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-item
              label="审批时间"
              :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formApprove.contactInfo"
                disabled
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-item
              label="节点名称"
              :label-col="{ lg: { span: 5 }, sm: { span: 5 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formApprove.replier"
                disabled
              />
            </a-form-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-item
              label="滞留时间"
              :label-col="{ lg: { span:5 }, sm: { span: 5 } }"
              :wrapper-col="{ lg: { span: 18 }, sm: { span: 18 } }"
            >
              <BaseInput
                v-model="formApprove.contactInfo"
                disabled
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-modal>

    <ApprovalDetails
      :title="'审批流程信息'"
      :business-id="this.id"
      :visible="visibleState.auditProcess"
      @cancel="visibleState.auditProcess = false"
      @confirm="visibleState.auditProcess = false"
    />
    <selectApprover
      :business-id="businessId"
      :process-config="setProcessConfig"
    />
  </base-breadcrumb>
</template>

<script>
  import { STable, Ellipsis } from '@/components'
  import {addBasic ,getProjectType,getDetails ,getMattersByproject ,editBasic ,deleteMattes,getPosts} from '@/api/design/plotsPlan'
  import { getDepartConfig, getJobStaff, getUserBranch } from '@/api/project/projects'
  import { getDesignType,getProjectsDel} from '@/api/project/projects'
  import { themeChoose } from '@/mixin/mixin'
  import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
  import SelectDutyPeople from '@/components/Select/SelectDutyPeople'
  import { getAuditProject} from '@/api/themeChoose/themeChoose'
  import ApprovalDetails from '@/components/approvalDetails'

import { getEmployeesList } from '@/api/commons'
  const columns = [
    {
      title: '序号',
      dataIndex: 'serial',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '计划事项',
      dataIndex: 'matter'
    },
    {
      title: '计划时间',
      dataIndex: 'time',

    },
    {
      title: '责任人',
      dataIndex: 'person',

    },
    {
      title: '责任人员工编号',
      dataIndex: 'personNum',
    },
    {
      title: '责任人岗位',
      dataIndex: 'posts',
      scopedSlots: { customRender: 'posts' }
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
  ]

  const  columnApprove = [
    {
      title: '审批序号',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '审批人',
      dataIndex: '',
    },
    {
      title: '审批时间',
      dataIndex: '',
    },
    {
      title: '节点名称',
      dataIndex: '',
    },
    {
      title: '滞留时间',
      dataIndex: '',
    },
    {
      title: '审批意见',
      dataIndex: '',
    },
    {
      title: '操作',
      dataIndex: 'operation',
      scopedSlots: { customRender: 'operation' }
    }
  ]

  export default {
    name:'a'+ Date.now(),
    mixins:[themeChoose],
    components:{
      Ellipsis,
      STable,
      SelectDutyPeople,
      ApprovalDetails,
      SelectSubCompany
    },
    data(){
      this.columns = columns
      return{
        cacheInfo: {
          branchCompany: '', // 缓存的分公司ID
          list: [], // 缓存的项目列表信息，当所选分公司和缓存的分公司一致时，需要将缓存的项目列表和查询出来的项目列表一起返回
        },
        loadingState: {
          isDraft: false,
          isSubmit: false,
          isProject: false,
        },
        visibleState: {
          auditProcess: false
        },
        editTargetIndex:null, // 重置序号
        ifReplace: null, // 是否替换小组成员
        // 查询参数
        queryParam: {},
        formAdd:{
          posts:'',
        },
        type:'',
        personList:[],
        loading:false,
        dataSource:[],
        tableData:[],
        tableData1:[
          {matter:'设计策划启动',id:'1'},
          {matter:'提交商务盈亏分析（导向分析）',id:'2'},
          {matter:'设计策划（设计策划书初稿、设计优化立项计划）评审',id:'3'},
        ],
        tableData2:[
          {matter:'《设计策划书》上报评审',id:'4'}
        ],
        confirmLoading:false,
        projectNames:[],
        approveVisible:false,
        projectList:[],

        name:'',
        basic:{
          branchCompany:'',
          projectName:'',
          num:'',
          designType:'',
          inTime:'',
          person:'',
          time:'',
        },
        plan:{},
        resList:[],
        recordForm:[],
        columnApprove,
        titleName:'',
        orgTree:[],
        formApprove:{},
        status:'',
        pageType:'',
        jobsList:[],
        form:{
          time:this.getNowTime()
        },
        visible:false,
        id:'',
        orgId:'',
        selectedRowKeys:[],
        selectedRows:[],
        rules: {
            inTime: [{ required: true, message: '请选择项目进场时间', trigger: 'change' }],
            branchCompany: [{ required: true, message: '请选择分公司', trigger: 'change' }],
            projectId: [{ required: true, message: '请选择项目', trigger: 'change' }],
        },
        rules1: {
            matter: [{ required: true, message: '请填写计划事项', trigger: 'blur' }],
            time: [{ required: true, message: '请选择计划时间', trigger: 'change' }],
            personId: [{ required: true, message: '请选择责任人', trigger: 'change' }],
        },
        //获取流程配置值
        processConfig: null,
        //点击提交发送流程配置值
        setProcessConfig: null,
        businessId: null
      }
    },
    computed:{
      realProjectList() {
        if(this.form.branchCompany === this.cacheInfo.branchCompany) {
          return this.cacheInfo.list.concat(this.projectList)
        }
        return this.projectList
      }
    },
   async created() {
      this.form.personName = JSON.parse(sessionStorage.getItem('ycloud-user_info')).employee.name
      this.orgId = JSON.parse(sessionStorage.getItem('ycloud-user_info')).orgId
      this.id = this.$route.query.id
      this.type = this.$route.query.type
      if(this.id){
        this.getDetails()
        console.log(this.projectList)
      }
      //获取通过获取流程配置值
      this.processConfig = await this.$getConfigFn('project_design_plan_sked')

      // this.getorgTree()
    },
    methods:{
      selectOrg(val) {
        if(val.length > 1) {
          this.form.branchCompany = val[val.length - 2].orgId
          if(this.type === 'add') {
            this.changeProjectType(this.form.projectId)
          }
        }
      },
      handleOrgChange(val) {
        if(val.length > 1) {
          this.form.branchCompany = val[val.length - 2].orgId
          this.changeProjectType(this.form.projectId)
        }
      },
      clearData(){
        this.form = {
          ...this.form,
          projectId: '',
          num: '',
          designType: '',
          designTypeId: '',
        }
      },
      handleSub(record,type){
        this.approveVisible = true
        this.type = type
        this.formApprove = record
      },
      changePerson(value){
        let that = this;
        let arr = []
        arr=that.personList.filter(item=>item.id==value)[0]

        that.formAdd.person = arr.name
        that.formAdd.personNum = arr.jobNum

        getPosts({id:arr.userId}).then(res=>{
          const list = res.data || []
          this.$set(this.formAdd, 'posts', list.map(item => item.pname).join(','))
        })
      },
      save(){
        console.log(this.form)
        // addBasic(this.basic).then((res)=>{
        //   if(res){
        //     this.$message.success("保存成功")
        //   }
        // })
      },
      getOrgUsers(){
        this.loading=true
        getEmployeesList({orgPath:this.form.branchCompany}).then(res=>{
          this.personList = res.data
          this.loading=false
        })
      },
      getDetails(){
        if(this.id){
          getDetails({id:this.id}).then(res=>{
            this.$nextTick(()=>{
              // this.form.projectId = res.data.projectId
            })
            this.form = {...res.data}
            if(!this.form.projectId){
              this.form.projectId = res.data.branchId
            }
          getAuditProject({branchComIds:[this.form.branchCompany],pageNo:1,pageSize:1000,designTypeNames:['C类','B类'],ifDesignPlan:0,auditStatus:2}).then(res=>{
            this.projectList = res.data
            let arr = {}
            arr={
              projectName:this.form.projectName,
              designTypeName:this.form.designType,
              designTypeId:this.form.designTypeId,
              projectNumber:this.form.num,
              projectId:this.form.projectId,
            }
            this.projectList.push(arr)
            console.log(this.projectList)
              this.cacheInfo = {
              branchCompany: this.form.branchCompany,
              list: [arr]
            }
          })
          })
          getMattersByproject({id:this.id}).then(res=>{
            this.tableData = res.data
          })
        }
      },
      getPopupContainer(triggerNode){
        return  triggerNode.parentNode
      },
      goDel(){
        if(this.selectedRows.length == 0){
          this.$message.error("请选择删除的计划项！")
          return;
        }
        this.$confirm({
          title: '提醒',
          content: '是否确认删除计划项？',
          onOk: () => {

            this.selectedRows.forEach((delItem,index)=>{
              this.tableData = this.tableData.filter((items)=> delItem.matter != items.matter)
            })

            this.$message.success("删除成功！")
            this.selectedRows = []
            this.selectedRowKeys = []
          }
        })
      },
      onChange(value){

      },
      changeTime(value,dateString){
        this.form.inTime = dateString
      },
      changeTimes(value,dateString){
        this.formAdd.time = dateString
      },
      selectType(value){
        console.log(value)
      },
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      changeProjectType(value){
        this.tableData = []
        console.log(value)
        let arr=[]
        arr.push(value)
        getProjectType({projectIds:arr}).then(res=>{
          console.log(res.data[0])
          this.form.num = res.data[0].projectNumber
          this.form.designType = res.data[0].designTypeName
          this.form.designTypeId = res.data[0].designTypeId
          if(this.form.designType=="B类"){
            this.tableData.push(
          {matter:'设计策划启动',id:'1'},
          {matter:'提交商务盈亏分析（导向分析）',id:'2'},
          {matter:'设计策划（设计策划书初稿、设计优化立项计划）评审',id:'3'}
          )
          }else if(this.form.designType=="C类"){
            this.tableData.push(
              {matter:'《设计策划书》上报评审',id:'4'}
            )
          }

        })
        // this.form.designType = this.form.typeList.designTypeName
        // this.form.num = this.form.typeList.projectNumber
      },
      getProjectTypes(){
        this.loadingState.isProject = true
        this.projectList = []
        getAuditProject({branchComIds:[this.form.branchCompany],pageNo:1,pageSize:1000,designTypeNames:['C类','B类'],ifDesignPlan:0,auditStatus:2}).then(res=>{
          this.projectList = res.data || []
          this.loadingState.isProject = false
          console.log(this.projectList)
        }).catch(() => {
          this.loadingState.isProject = false
        })
      },
      getPosts(value) {
        this.projectId = value
      },

      onSelectChange(selectedRowKeys, selectedRows) {
        console.log(selectedRowKeys)
        console.log(selectedRows)
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      // 保存草稿---提交
      saveForm(type){
        this.$refs.ruleForm.validate(valid=>{
          if(valid){
            this.tableData.forEach(item=>{
              item.id=null
            })
            this.form.list = this.tableData
              this.form.statusCode = '0'
              if(this.loadingState.isDraft) return
              this.loadingState.isDraft = true
              if(this.id){
                editBasic(this.form).then(res=>{
                  this.loadingState.isDraft = false
                  this.$multiTab.close(this.$route.fullpath)
                  if(res.code='200'){
                    this.$message.success("保存成功")
                  }
                }).catch(e => {
                  this.loadingState.isDraft = false
                })
              }else{
                addBasic(this.form).then(res=>{
                  this.loadingState.isDraft = false
                  this.$multiTab.close(this.$route.fullpath)
                  if(res.code='200'){
                        this.$message.success("保存成功")
                  }
                }).catch(e => {
                  this.loadingState.isDraft = false
                })
              }
          }
        })
      },
      saveSubmit(){
        let that = this
        that.setProcessConfig = null;
        that.$refs.ruleForm.validate(valid=>{
          if(valid){
            that.tableData.forEach(item=>{
              item.id=null
            })
            that.form.list = that.tableData
            console.log(this.form)
            if(that.form.list.length==0){
              that.$message.error("请填写计划项")
            }else{
              let matterList=[]
              let timeList=[]
              let personList=[]
              that.form.list.forEach(item=>{

                matterList.push(item.matter)
                if(item.time != undefined){
                  timeList.push(item.time)
                }
                if(item.personId != undefined){
                  personList.push(item.personId)
                }

              })
              if((matterList.length == that.form.list.length) && ( timeList.length == that.form.list.length) && (personList.length == that.form.list.length)){
                that.form.statusCode = '1'
                if(that.loadingState.isSubmit) return
                that.loadingState.isSubmit = true
                if(that.id){
                  editBasic(that.form).then(res=>{
                    that.loadingState.isSubmit = false
                    if(res.code='200'){
                      that.$message.success("提交成功")
                      //提交时，返回id
                      that.businessId = res.data.id;
                      that.setProcessConfig = that.processConfig;
                    }
                  }).catch(() => {
                    that.loadingState.isSubmit = false
                  })
                }else{
                  addBasic(that.form).then(res=>{
                    that.loadingState.isSubmit = false
                    if(res.code='200'){
                      that.$message.success("提交成功")
                      //提交时，返回id
                      that.businessId = res.data.id;
                      that.setProcessConfig = that.processConfig;
                    }
                  }).catch(() => {
                    that.loadingState.isSubmit = false
                  })
                }
              }else{
                that.$message.error("请将计划项信息填写完整再提交")
              }
            }
          } else {
            this.$message.warning('请填写完所有必填项信息')
          }
        })
      },
      search(){
        this.$refs.table.refresh(true)
      },
      goAdd(){
        this.editTargetIndex = null // 重置序号
        this.ifReplace = null // 重置编辑标识
        this.titleName = '新增计划项'
        this.visible = true
        this.getOrgUsers()
        this.formAdd = {}
      },
      // 关闭
      goBack(){
        this.$multiTab.close(this.$route.fullpath)
      },
      handleEdit(record,index){
        this.recordForm = JSON.parse(JSON.stringify(this.tableData))
        this.titleName= '编辑计划项'
        this.visible = true
        this.editTargetIndex = index
        this.ifReplace = 1 // 重置编辑标识
        this.formAdd = {...record}
        this.getOrgUsers()
      },
      handleOk(){
        let that = this
        that.$refs.ruleForm1.validate(valid=>{
          if(valid){
            that.visible = false

            if(that.id){
              // 编辑
              if(that.ifReplace == 1){
                that.tableData.splice(that.editTargetIndex, 1, { ...that.formAdd })
                that.editTargetIndex = null
              }else{
                that.tableData.push(that.formAdd)
              }
            }else{
              // 新增
              if(that.ifReplace == 1){
                that.tableData.splice(that.editTargetIndex, 1, { ...that.formAdd })
                that.editTargetIndex = null
              }else{
                that.tableData.push(that.formAdd)
              }

            }
          }
        })
      },
      handleCancel(){
        console.log(this.formAdd.id)
        if(this.formAdd.id){
        this.tableData = this.recordForm
        }
        this.visible = false
      }
    }
  }
</script>

<style scoped>
  .input{
    width:100%
  }
  .footer{
    float:right;
    margin-right:10px
  }
  .footer button{
    margin-left:10px
  }
</style>
